`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2017/10/23 15:27:24
// Design Name: 
// Module Name: aludec
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////

`include "op.vh"
`include "funct.vh"
`include "alucontrol.vh"
`include "op.vh"
`include "funct.vh"

module aludec(
	input wire[31:0] instr,
	output reg[4:0] alucontrol
    );
    wire [5:0] op;
    wire [5:0] funct;
    wire [4:0] rt;
    wire [4:0] rs;
    assign op = instr[31:26];
    assign funct = instr[5:0];
    assign rt = instr[20:16];
    assign rs = instr[25:21];
    assign alucontrol = (op == `SPECIAL_OP && funct == `FUNCT_AND) ? `ALUCONTROL_AND:
                                    (op == `SPECIAL_OP && funct == `FUNCT_OR) ? `ALUCONTROL_OR:
                                    (op == `SPECIAL_OP && funct == `FUNCT_NOR) ? `ALUCONTROL_NOR:
                                    (op == `SPECIAL_OP && funct == `FUNCT_XOR) ? `ALUCONTROL_XOR:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SLL) ? `ALUCONTROL_SLL:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SRL) ? `ALUCONTROL_SRL:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SRA) ? `ALUCONTROL_SRA:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SLLV) ? `ALUCONTROL_SLLV:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SRLV) ? `ALUCONTROL_SRLV:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SRAV) ? `ALUCONTROL_SRAV:
                                    (op == `SPECIAL_OP && funct == `FUNCT_ADD) ? `ALUCONTROL_ADD:
                                    (op == `SPECIAL_OP && funct == `FUNCT_ADDU) ? `ALUCONTROL_ADDU:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SUB) ? `ALUCONTROL_SUB:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SUBU) ? `ALUCONTROL_SUBU:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SLT) ? `ALUCONTROL_SLT:
                                    (op == `SPECIAL_OP && funct == `FUNCT_SLTU) ? `ALUCONTROL_SLTU:
                                    (op == `SPECIAL_OP && funct == `FUNCT_MULT) ? `ALUCONTROL_MULT:
                                    (op == `SPECIAL_OP && funct == `FUNCT_MULTU) ? `ALUCONTROL_MULTU:
                                    (op == `SPECIAL_OP && funct == `FUNCT_DIV) ? `ALUCONTROL_DIV:
                                    (op == `SPECIAL_OP && funct == `FUNCT_DIVU) ? `ALUCONTROL_DIVU:
                                    (op == `OP_SB) ? `ALUCONTROL_ADD:
                                    (op == `OP_SH) ? `ALUCONTROL_ADD:
                                    (op == `OP_LB) ? `ALUCONTROL_ADD:
                                    (op == `OP_LBU) ? `ALUCONTROL_ADD:
                                    (op == `OP_LH) ? `ALUCONTROL_ADD:
                                    (op == `OP_LHU) ? `ALUCONTROL_ADD:
                                    (op == `OP_LHU) ? `ALUCONTROL_ADD:
                                    (op == `SPECIAL_OP && funct == `FUNCT_MFHI) ? `ALUCONTROL_MFHI:
                                    (op == `SPECIAL_OP && funct == `FUNCT_MFLO) ? `ALUCONTROL_MFLO:
                                    (op == `SPECIAL_OP && funct == `FUNCT_MTHI) ? `ALUCONTROL_MTHI:
                                    (op == `SPECIAL_OP && funct == `FUNCT_MTLO) ? `ALUCONTROL_MTLO:
                        
                                    (op == `OP_ANDI) ? `ALUCONTROL_AND:
                                    (op == `OP_ORI) ? `ALUCONTROL_OR:
                                    (op == `OP_XORI) ? `ALUCONTROL_XOR:
                                    (op == `OP_LUI) ? `ALUCONTROL_LUI:
                                    (op == `OP_LW) ? `ALUCONTROL_ADD:
                                    (op == `OP_SW) ? `ALUCONTROL_ADD:
                                    (op == `OP_ADDI) ? `ALUCONTROL_ADD:
                                    (op == `OP_ADDIU) ? `ALUCONTROL_ADDU:
                                    (op == `OP_SLTI) ? `ALUCONTROL_SLT:
                                    (op == `OP_SLTIU) ? `ALUCONTROL_SLTU:
                                    (op == `OP_JAL) ? `ALUCONTROL_ADDU:
                                    (op == `OP_JALR) ? `ALUCONTROL_ADDU:
                                    (op == `OP_BLTZAL) ? `ALUCONTROL_ADDU:
                                    (op == `OP_BGEZAL) ? `ALUCONTROL_ADDU:
                                    (op == `OP_MTC0 && rs == 5'b00100) ? `ALUCONTROL_MTC0:
                                    (op == `OP_MFC0 && rs == 5'b000000) ? `ALUCONTROL_MFC0:
                                    5'b11111;
endmodule
